﻿using System;
using System.Collections;
using System.Text;
using Peekaboo2008.model;
using System.Data;
using Peekaboo2008.util;
using System.Data.SqlClient;

namespace Peekaboo2008.dao
{
    class ChiNhanhDAO
    {
        public static DataTable getAll()
        {    
            return  DataUtil.executeStore("sp_ChiNhanh_GetALL",null);  

        }

        public static ChiNhanhModel getByMaChiNhanh(String _maChiNhanh)
        {
            ChiNhanhModel model = new ChiNhanhModel();
            SqlParameter[] param = new SqlParameter[1];
            int i = 0;
            param[i] = new SqlParameter("Ma_chi_nhanh", SqlDbType.NVarChar);
            param[i++].Value = _maChiNhanh;

            DataTable dt =  DataUtil.executeStore("sp_ChiNhanh_GetByMaChiNhanh", param);
            try
            {
                foreach (DataRow dr in dt.Rows)
                {
                    model.MaChiNhanh = dr["ID"].ToString();
                    model.MaKhuVuc = dr["Ma_khu_vuc"].ToString();
                    model.TenChiNhanh = dr["Ten"].ToString();
                    model.Tel = dr["Tel"].ToString();
                    model.DiaChi = dr["Dia_chi"].ToString();
                    model.TruongChiNhanh = dr["Truong_chi_nhanh"].ToString();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace.ToString());
            }
            return model;
        }

        public static DataTable GopTenVaDiaChi()
        {
            return DataUtil.executeStore("[sp_ChiNhanh_GopTenVaDiaChi]", null);
        }
    }
}
